package com.kaiyiweitong.tongxing.activity.my;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.kaiyiweitong.tongxing.R;
import com.kaiyiweitong.tongxing.activity.my.person_info.SetNicknameActivity;
import com.kaiyiweitong.tongxing.activity.my.person_info.SetSexActivity;
import com.kaiyiweitong.tongxing.base.BaseActivity;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/12/19 0019.
 */

public class PersonInfoActivity extends BaseActivity {
    @Bind(R.id.iv_person_icon)
    ImageView mIvPersonIcon;
    @Bind(R.id.tv_nick_name)
    TextView mTvNickName;
    @Bind(R.id.tv_sex)
    TextView mTvSex;
    @Bind(R.id.tv_birthday)
    TextView mTvBirthday;
    @Bind(R.id.phone_num)
    TextView mPhoneNum;
    @Bind(R.id.wechat_num)
    TextView mWechatNum;
    private TimePickerView pvTime;
    private String sex;
    private String sex1;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_info);
        ButterKnife.bind(this);
        init();
        initTimePicker();

    }

    @OnClick({R.id.rl_person_icon, R.id.rl_nick_name, R.id.rl_sex, R.id.rl_birthday})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_person_icon:
                setPic();
                break;
            case R.id.rl_nick_name:
                go2Page(SetNicknameActivity.class);
                break;
            case R.id.rl_sex:

                go2Page(SetSexActivity.class);
                break;
            case R.id.rl_birthday:
                pvTime.show(view);
                break;
        }
    }

    private void go2Page(Class clazz) {
        Intent intent = new Intent(this, clazz);

        startActivity(intent);
    }

    private void initTimePicker() {
        Calendar selectedDate = Calendar.getInstance();
        Calendar startDate = Calendar.getInstance();
        startDate.set(1900, 0, 23);
        Calendar endDate = Calendar.getInstance();
        endDate.set(2019, 11, 28);
        pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                mTvBirthday.setText(getTime(date));

            }
        }).setCancelText("取消")
                .setSubmitText("确认")
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("年", "月", "日", "", "", "")
                .isCenterLabel(false)
                .setDividerColor(Color.DKGRAY)
                .setContentSize(21)
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .setDecorView(null)
                .build();
    }

    private String getTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }

    private void setPic() {

    }

    private void init() {

    }
}
